<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>
        <h1 class="pull-right">
            <a href="<?php echo $this->url('operation-coupon'); ?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回优惠券列表'); ?></a>
            <?php echo $this->HelpUrl('coupon'); ?>
        </h1>
    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box shop-box">
                    <h2 class="page-header" style="padding-left: 10px;padding-top: 10px;">
                        <?php echo $this->escapeHtml($this->couponInfo->getCouponTitle()); ?>
                    </h2>
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead>
                            <tr class="shop-bg-thead">
                                <th width="15%"><?php echo $this->translate('获得者'); ?></th>
                                <th width="20%"><?php echo $this->translate('获得时间'); ?></th>
                                <?php if ($this->couponInfo->getGetCouponType() == 'buy') { ?>
                                    <th width="15%"><?php echo $this->translate('订单编号(获得)'); ?></th>
                                <?php } ?>
                                <th width="10%"><?php echo $this->translate('状态'); ?></th>
                                <th width="15%"><?php echo $this->translate('订单编号(已用)'); ?></th>
                                <th width="20%" colspan="2"><?php echo $this->translate('时间(已用)'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('coupon_use_state')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <td>
                                    <?php echo $this->formElement($sForm->get('user_name')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('user_name'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('get_start_time')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('get_end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('get_start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('get_end_time'), ['class'=>'error-message']);?>
                                </td>
                                <?php if ($this->couponInfo->getGetCouponType() == 'buy') { ?>
                                    <td>
                                        <?php echo $this->formElement($sForm->get('get_order_sn')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('get_order_sn'), ['class'=>'error-message']);?>
                                    </td>
                                <?php } ?>
                                <td>
                                    <?php echo $this->formElement($sForm->get('coupon_use_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('coupon_use_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('use_order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('use_order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('use_start_time')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('use_end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('use_start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('use_end_time'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php
                                    $couponUseState = $sForm->get('coupon_use_state')->getValue();
                                    $formData = array_filter($sForm->getData());
                                    if(!empty($formData)  || (is_numeric($couponUseState) && $couponUseState >= 0)) { ?>
                                        &nbsp;&nbsp;<a href="<?php echo $this->url('operation-coupon', ['action' => 'userCouponList', 'id' => $this->couponInfo->getCouponId()]);?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>
                            <tbody>
                            <?php if($this->userCouponList->getCurrentItemCount() > 0) foreach ($this->userCouponList as $couponValue) { ?>
                                <tr>
                                    <td><?php echo $this->escapeHtml($couponValue->getUserName()); ?></td>
                                    <td><?php echo $this->shopDateFormat()->couponTime($couponValue->getGetTime()); ?></td>
                                    <?php if ($this->couponInfo->getGetCouponType() == 'buy') { ?>
                                        <td><?php echo $this->escapeHtml($couponValue->getGetOrderSn()); ?></td>
                                    <?php } ?>
                                    <td><?php echo $this->userCouponStateArray[$couponValue->getCouponUseState()]; ?></td>
                                    <td><?php echo $this->escapeHtml($couponValue->getUsedOrderSn()); ?></td>
                                    <td colspan="2"><?php echo $couponValue->getUsedTime() > 0 ? $this->shopDateFormat()->couponTime($couponValue->getUsedTime()) : ''; ?></td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?php echo $this->paginationControl($this->userCouponList, 'Sliding', 'layout/page', ['route' => 'operation-coupon', 'params' => ['action' => 'userCouponList', 'id' => $this->couponInfo->getCouponId()]]); ?>
                    </div>
                </div>
            </div>
        </div>

    </section>
</div>
<script>
    laydate.render({elem: '#get_start_time'});
    laydate.render({elem: '#get_end_time'});
    laydate.render({elem: '#use_start_time'});
    laydate.render({elem: '#use_end_time'});
</script>